//
//  FRLiveHandler.m
//  Live
//
//  Created by 徐芙蓉 on 2017/8/2.
//  Copyright © 2017年 Afra. All rights reserved.
//

#import "FRLiveHandler.h"
#import "HttpTool.h"
#import "FRLive.h"
#import "FRLocationManager.h"
#import "FRAdvertise.h"

@implementation FRLiveHandler
+ (void)executeGetHotLiveTaskWithSuccess:(SuccessBlock)success failed:(FailedBlock)failed
{
    [HttpTool getWithPath:API_HotLive params:nil success:^(id json) {
        
        if ([json[@"dm_error"] integerValue]) {
            failed(json);
        } else {
            //如果返回信息正确
            //数据解析
            NSArray *lives = [FRLive mj_objectArrayWithKeyValuesArray:json[@"lives"]];
            success(lives);
        }
        
//        success(json);
        
    } failure:^(NSError *error) {
        
        failed(error);
        
    }];
    
}

+(void)executeGetNearLiveTaskWithSuccess:(SuccessBlock)success failed:(FailedBlock)failed
{
//    FRLocationManager *manager = [FRLocationManager sharedManager];
//    NSDictionary *params = @{@"uid":@"85149891", @"latitude":manager.lat,@"longitude":manager.lon};
    NSDictionary *params = @{@"uid":@"85149891", @"latitude":@"40.090562",
                             @"longitude":@"116.413353"};
    [HttpTool getWithPath:API_NearLive params:params success:^(id json) {
        
        if ([json[@"dm_error"] integerValue]) {
            failed(json);
        } else {
            //如果返回信息正确
            //数据解析
            NSArray *lives = [FRLive mj_objectArrayWithKeyValuesArray:json[@"lives"]];
            success(lives);
        }
        
//        success(json);
        
    } failure:^(NSError *error) {
        failed(error);
    }];
}

+(void)executeGetAdvertiseTaskWithSuccess:(SuccessBlock)success failed:(FailedBlock)failed
{
    [HttpTool getWithPath:API_Advertise params:nil success:^(id json) {
        
        if ([json[@"dm_error"] integerValue]) {
            failed(json);
        } else {
            FRAdvertise *advertise = [FRAdvertise mj_objectWithKeyValues:json[@"resources"][0]];
            success(advertise);
        }
        
    } failure:^(NSError *error) {
        failed(error);
    }];
}

@end
